package com.wl.dzt.sys.util;


import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * @author wl_code@163.com
 * @version 1.0
 * @date 2018/7/2/002
 * @description Spring 工具
 */
public class SpringUtil {

    /**
     * 获取bean
     *
     * @param id
     * @param <T>
     * @return
     */
    public static <T> T getBean(String id) {
        if (id == null)
            return null;
        return (T) ApplicationContextRegister.getApplicationContext().getBean(id);
    }

    /**
     * 获取bean
     *
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T getBean(Class<T> clazz) {
        if (clazz == null)
            return null;
        return clazz == null ? null : com.wl.dzt.sys.util.ApplicationContextRegister.getApplicationContext().getBean(clazz);
    }

    /**
     * 事务回滚
     *
     * @return
     */
    public static boolean rollback() {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return false;
    }

}
